package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Room {
    public static final int BREAKFAST_YES=0; //  含早餐
    public static final int BREAKFAST_NO=1; //  不含

    public static final int TYPE_CHECKIN=0; //  已入住
    public static final int TYPE_CHECKOUT=1; //  可入住


    public static final int BED_ONE=0; //  标准间
    public static final int BED_TOW=1; //  双人间
    public static final int BED_BIG=2; //  大床房
    public static final int BED_PRES=3; //  总统套房

    private Long id;

    private String titel;  //标题

    private Integer area;  //面积

    private Integer breakfast;  //早餐

    private Integer bed;  //床

    private String coverUrl;  //图片

    private Integer price;  //价格

    private Integer type;  //状态
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date checkInTime;  //入住时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date checkOutTime;  //离店时间

    private User user;  //用户

    private Hotel hotel;  //酒店ID

    public String getBreakfastDisplay(){
        if(breakfast == BREAKFAST_YES){
            return "含早餐";
        }else if(breakfast == BREAKFAST_NO){
            return "不含";
        }
        return "";
    }
    public String getTypeDisplay(){
        if(type == TYPE_CHECKOUT){
            return "未入住";
        }else if(type == TYPE_CHECKIN){
            return "已入住";
        }
        return "";
    }
    public String getBedDisplay(){
        if(bed == BED_ONE){
            return "标准间";
        }else if(bed == BED_TOW){
            return "双人间";
        }else if(bed == BED_BIG){
            return "大床房";
        }else if(bed == BED_PRES){
            return "总统套房";
        }
        return "";
    }
    public String getJsonString(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("titel",titel);
        map.put("area",area);
        map.put("breakfast",breakfast);
        map.put("bed",bed);
        map.put("coverUrl",coverUrl);
        map.put("price",price);
        map.put("type",type);
        if(checkInTime !=null){
            map.put("checkInTime", DateUtil.date2string(checkInTime,"yyyy-MM-dd HH:mm:ss") );
        }
        if(checkOutTime !=null){
            map.put("checkOutTime",DateUtil.date2string(checkOutTime,"yyyy-MM-dd HH:mm:ss"));
        }
        if(user != null){
            map.put("userId",user.getId());
            map.put("userNickName",user.getNickName());
        }
        if(hotel != null){
            map.put("hotelId",hotel.getId());
            map.put("hotelTitle",hotel.getTitle());
        }
        return JSONUtils.toJSONString(map);
    }
}